﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using lumo.display.object2D;
using lumo.display.animation2D;

namespace lumo.display.gui
{
    /// <summary>
    /// A custom positionable command list.
    /// </summary>
    public class CustomPositionableCommandList : PositionableCommandListBase
    {
        /// <summary>
        /// Item offset class.
        /// </summary>
        public class ItemOffset
        {
            // Private variables.
            private List<Vector2> _List = new List<Vector2>();
            private CustomPositionableCommandList _Parent;

            /// <summary>
            /// Private constructor.
            /// </summary>
            /// <param name="Parent">Parent.</param>
            internal ItemOffset(CustomPositionableCommandList Parent)
            {
                _Parent = Parent;
            }

            /// <summary>
            /// Property for indexer.
            /// </summary>
            /// <param name="index">The index</param>
            /// <returns>The offsets</returns>
            public Vector2 this[int index]
            {
                get
                {
                    if ((index < 0) || (index >= _Parent.Count))
                        throw new Exception("Invalid index");
                    while (_List.Count != _Parent.Count)
                        _List.Add(Vector2.Zero);
                    return _List[index];
                }
                set
                {
                    if ((index < 0) || (index >= _Parent.Count))
                        throw new Exception("Invalid index");
                    while (_List.Count != _Parent.Count)
                        _List.Add(Vector2.Zero);
                    _List[index] = value;
                }
            }
        }
        
        // Offset of item
        public readonly ItemOffset Offset;

        /// <summary>
        /// Constructor.
        /// </summary>
        public CustomPositionableCommandList()
        {
            Offset = new ItemOffset(this);
        }
        
        /// <summary>
        /// Get the item offset.
        /// </summary>
        /// <param name="Index">Index of the item.</param>
        /// <returns>The offset.</returns>
        protected override Vector2 GetItemOffset(int Index)
        {
            return Offset[Index];
        }
    }
}
